//
//  MarriagePlanSectionHeaderView.m
//  BaseProject
//
//  Created by mac on 2020/11/20.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MarriagePlanSectionHeaderView.h"
#import "MarriagePlanModel.h"
@interface MarriagePlanSectionHeaderView ()
@property(nonatomic,strong)UIView *bgView;
@property(nonatomic,strong)UIImageView *leftIV;
@property(nonatomic,strong)UILabel *titleLab;
@property(nonatomic,strong)BaseAdjustButton *rightButton;
@property(nonatomic,strong)UILabel *numsLab;
@end

@implementation MarriagePlanSectionHeaderView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = RGB(255, 255, 255);
        self.contentView.backgroundColor = RGB(255, 255, 255);
        
        [self bgView];
    }
    return self;
}
- (void)setSectionModel:(MarriagePlanSectionModel *)sectionModel
{
    _sectionModel = sectionModel;
    if ([sectionModel.plansTime isEqualToString:@"0"]) {
        self.leftIV.image = [UIImage getPNGimageInBundleWithName:@"MarrayPlan_task"];
        self.leftIV.frame = CGRectMake(15*ADAPTER_WIDTH, 13*ADAPTER_WIDTH, 22*ADAPTER_WIDTH, 23*ADAPTER_WIDTH);
        self.bgView.layer.shadowColor = rgba(230, 230, 230, 0).CGColor;
        self.bgView.layer.cornerRadius = 0;
    } else {
        self.leftIV.image = [UIImage getPNGimageInBundleWithName:@"MarrayPlan_Circle"];
        self.leftIV.frame = CGRectMake(20*ADAPTER_WIDTH, 18*ADAPTER_WIDTH, 12*ADAPTER_WIDTH, 13*ADAPTER_WIDTH);
        self.bgView.layer.cornerRadius = 10*ADAPTER_WIDTH;
        self.bgView.layer.shadowColor = rgba(230, 230, 230, 1).CGColor;
    }
    self.titleLab.centerY = self.leftIV.centerY;
    self.titleLab.text = sectionModel.plansTimeContent;
    self.rightButton.selected = sectionModel.flex;
    self.numsLab.text = [NSString stringWithFormat:@"%ld/%ld",sectionModel.succeedNumber,sectionModel.originList.count];
}
#pragma mark - click
- (void)clickRightButton:sender
{
    if ([self.delegate respondsToSelector:@selector(marriagePlanSectionHeaderViewBackType:backSection:)]) {
        [self.delegate marriagePlanSectionHeaderViewBackType:0 backSection:self.section];
    }
}
#pragma mark - lazy懒加载
- (UIView *)bgView
{
    if (!_bgView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = RGB(255, 255, 255);
        view.frame = CGRectMake(0, 0, WIDTH, 50*ADAPTER_WIDTH);
        [self.contentView addSubview:view];
        view.layer.cornerRadius = 10*ADAPTER_WIDTH;
        //view.layer.masksToBounds = YES;
        view.layer.shadowColor = rgba(230, 230, 230, 1).CGColor;
        view.layer.shadowOffset = CGSizeMake(0, -2);
        view.layer.shadowRadius = 5;
        view.layer.shadowOpacity = 1;
        _bgView = view;
    }
    return _bgView;
}
- (UIImageView *)leftIV
{
    if (!_leftIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self.bgView addSubview:iv];
        _leftIV = iv;
    }
    return _leftIV;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = rgba(34, 34, 34, 1);
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(42*ADAPTER_WIDTH, 19*ADAPTER_WIDTH, WIDTH - 100*ADAPTER_WIDTH, 17*ADAPTER_WIDTH);
        _titleLab = lab;
    }
    return _titleLab;
}
- (BaseAdjustButton *)rightButton
{
    if (!_rightButton) {
        BaseAdjustButton *button = [BaseAdjustButton buttonWithType:UIButtonTypeCustom];
        [self.bgView addSubview:button];
        button.type = layoutTypeOnlyImage;
        button.imageWidth = 11*ADAPTER_WIDTH;
        button.imageHeight = 9*ADAPTER_WIDTH;
        button.marginLeft = WIDTH - 25*ADAPTER_WIDTH;
        button.marginRight = 14*ADAPTER_WIDTH;
        button.marginTop = 25*ADAPTER_WIDTH;
        button.marginBottom = 10*ADAPTER_WIDTH;
        [button begin];
        [button setImage:[UIImage getPNGimageInBundleWithName:@"MarrayPlan_triangle_down"] forState:UIControlStateNormal];
        [button setImage:[UIImage getPNGimageInBundleWithName:@"MarrayPlan_triangle_up"] forState:UIControlStateSelected];
        button.top = 0;
        button.right = self.bgView.width;
        [button addTarget:self action:@selector(clickRightButton:) forControlEvents:UIControlEventTouchUpInside];
        _rightButton = button;
    }
    return _rightButton;
}
- (UILabel *)numsLab
{
    if (!_numsLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = kColor51;
        lab.textAlignment = NSTextAlignmentRight;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(200*ADAPTER_WIDTH, 19*ADAPTER_WIDTH, self.bgView.width - 230*ADAPTER_WIDTH, 22*ADAPTER_WIDTH);
        _numsLab = lab;
    }
    return _numsLab;
}
@end
